var LRUCache = function (capacity) {
    this.cache = new Map();
    this.capacity = capacity;
};

/** 
 * @param {number} key
 * @return {number}
 */
LRUCache.prototype.get = function (key) {
    if(this.cache.has(key)){
        const value = this.cache.get(key);
        this.cache.delete(key);
        this.cache.set(key, value);
        return value;
    }
    return -1;
};

/** 
 * @param {number} key 
 * @param {number} value
 * @return {void}
 */
LRUCache.prototype.put = function (key, value) {
    if (this.cache.has(key)) {//修改
        this.cache.delete(key);
    } else if (this.cache.size >= this.capacity) {//新增
        const oldkey = this.cache.keys().next().value;
        this.cache.delete(oldkey);
    }
    this.cache.set(key, value);

};